package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.acticle.domain.Destination;
import cn.wolfcode.luowowo.acticle.domain.Region;
import cn.wolfcode.luowowo.acticle.query.RegionQuery;
import cn.wolfcode.luowowo.acticle.service.IRegionService;
import cn.wolfcode.luowowo.article.mapper.DestinationMapper;
import cn.wolfcode.luowowo.article.mapper.RegionMapper;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class RegionServiceImpl implements IRegionService {

    @Autowired
    private RegionMapper regionMapper;
    @Autowired
    private DestinationMapper destinationMapper;

    @Override
    public PageInfo queryForList(RegionQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        return new PageInfo(regionMapper.selectForList(qo));
    }

    @Override
    public List<Destination> getDestByDeep(int deep) {
        return destinationMapper.listByDeep(deep);
    }

    @Override
    public void saveOrUpdate(Region region) {
        if(region.getId()==null){
            regionMapper.insert(region);
        }else {
            regionMapper.updateByPrimaryKey(region);
        }
    }

    @Override
    public void delete(Long id) {
        regionMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<Region> getHotRegions() {
        return regionMapper.selectHotRegions();
    }
}
